<?php 
	
	// `auto generate sidebar content
	$main_cat = get_category_by_slug($post_type);
	$main_cat_id = $main_cat->term_id;
	
	$args = array(
			'child_of'                 => $main_cat_id,
			'orderby'                  => 'name',
			'order'                    => 'ASC');
	$categories = get_categories( $args );
	
	$_previews = false;
	$_downloads = false;
	$_installs = false;
	$_views = true;
	$_rate_up = true;
	$_comments = true;
	
	if ($post_type == 'templates') {
		$_previews = true;
		$_downloads = true;
	}
	if ($post_type == 'widgets') {
		$_installs = true;
	}
	
	
	// `sort by status
	$sidebar = '<h3>Sort by</h3>';        
	$sidebar .= '<ul>';
	$sidebar .= '<li><a method="sr" class="auto-side" href="#">All</a></li>';
	if ($_downloads) {
		$sidebar .= '<li><a method="sr" class="auto-side" data="downloads" href="#">Downloads</a></li>';
	}
	if ($_previews) {
		$sidebar .= '<li><a method="sr" class="auto-side" data="previews" href="#">Previews</a></li>';
	}
	if ($_installs) {
		$sidebar .= '<li><a method="sr" class="auto-side" data="installs" href="#">Installs</a></li>';
	}
	if ($_rate_up) {
		$sidebar .= '<li><a method="sr" class="auto-side" data="rate-up" href="#">Rate up</a></li>';
	}
	if ($_views) {
		$sidebar .= '<li><a method="sr" class="auto-side" data="views" href="#">Views</a></li>';
	}
	if ($_comments) {
		$sidebar .= '<li><a method="sr" class="auto-side" data="comments" href="#">Comments</a></li>';
	}
	$sidebar .= '</ul>';
			
	// `sort by subjects
	$sidebar .= '<h3>Subjects</h3>';        
	$sidebar .= '<ul>';
	$sidebar .= '<li><a method="su" class="auto-side" href="#">All</a></li>';
	foreach ($categories as $cat) {
			$sidebar .= '<li><a method="su" class="auto-side" data="'.$cat->slug.'" href="#">'.$cat->name.'</a></li>';
	}
	$sidebar .= '</ul>';
			
	echo $sidebar;
	?>